package cn.iocoder.yudao.module.wms.dal.mysql.customer;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.wms.controller.admin.customer.vo.CustomerPageReqVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.customer.CustomerDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 客户档案 Mapper
 *
 * @author 刘锦
 */
@Mapper
public interface CustomerMapper extends BaseMapperX<CustomerDO> {

    default PageResult<CustomerDO> selectPage(CustomerPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CustomerDO>()
                .likeIfPresent(CustomerDO::getCode, reqVO.getCode())
                .likeIfPresent(CustomerDO::getName, reqVO.getName())
                .eqIfPresent(CustomerDO::getAddress, reqVO.getAddress())
                .eqIfPresent(CustomerDO::getClassifyId, reqVO.getClassifyId())
                .orderByDesc(CustomerDO::getId));
    }

    default List<CustomerDO> selectList(String query) {
        return selectList(new LambdaQueryWrapperX<CustomerDO>()
                .like(CustomerDO::getCode,query)
                .or()
                .like(CustomerDO::getName,query)
                .orderByDesc(CustomerDO::getCode)
                .last("limit 100"));
    }

}